//
//  MAMgrPopView.m
//  meiang_edu
//
//  Created by hfcb on 2018/9/9.
//  Copyright © 2018年 com.meiang.meiang_edu. All rights reserved.
//

#import "MAMgrPopView.h"

@interface MAMgrPopView ()
@property (weak, nonatomic) IBOutlet UIButton *firstBtn;
@property (weak, nonatomic) IBOutlet UIButton *secondBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *secondBtnHeightCons;
@property (weak, nonatomic) IBOutlet UIButton *thirdBtn;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *thirdBtnHeightCons;
@property (weak, nonatomic) IBOutlet UIView *secondLine;

@end

@implementation MAMgrPopView

- (void)awakeFromNib {
    [super awakeFromNib];
    self.autoresizingMask = UIViewAutoresizingNone;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self = [[[NSBundle mainBundle] loadNibNamed:NSStringFromClass([self class]) owner:nil options:nil] lastObject];
    }
    return self;
}
+ (instancetype)popViewWithTitles:(NSArray *)titles clickBlock:(MyBlock)clickBlock {
    MAMgrPopView *popView = [[MAMgrPopView alloc] init];
    
    popView.width = 160;
    popView.height = 43.5 * titles.count;
    
    if (titles.count == 1) {
        [popView.firstBtn setTitle:titles[0] forState:UIControlStateNormal];
        popView.secondBtnHeightCons.constant = 0;
        popView.secondBtn.hidden = YES;
        popView.thirdBtnHeightCons.constant = 0;
        popView.thirdBtn.hidden = YES;
    } else if (titles.count == 2) {
        [popView.firstBtn setTitle:titles[0] forState:UIControlStateNormal];
        [popView.secondBtn setTitle:titles[1] forState:UIControlStateNormal];
        popView.secondBtnHeightCons.constant = 43.5;
        popView.secondBtn.hidden = NO;
        popView.thirdBtnHeightCons.constant = 0;
        popView.thirdBtn.hidden = YES;
    } else if (titles.count == 3) {
        [popView.firstBtn setTitle:titles[0] forState:UIControlStateNormal];
        [popView.secondBtn setTitle:titles[1] forState:UIControlStateNormal];
        [popView.thirdBtn setTitle:titles[2] forState:UIControlStateNormal];
        popView.secondBtnHeightCons.constant = 43.5;
        popView.secondBtn.hidden = NO;
        popView.thirdBtnHeightCons.constant = 43.5;
        popView.thirdBtn.hidden = NO;
    }
    if (clickBlock) {
        popView.clickIndexBlock = clickBlock;
    }
    return popView;
}
- (IBAction)btnDidClick:(UIButton *)sender {
    if (self.clickIndexBlock) {
        self.clickIndexBlock(sender.tag);
    }
}

@end
